﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Geolocation;

namespace Smile.Mvvm.Service.Geolocation
{
    public class GeolocationService : IGeolocationService
    {
        public async Task<ICoordinate> GetDevicePositionAsync()
        {
            var geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;

            try
            {
                var geoposition = await geolocator.GetGeopositionAsync(
                    TimeSpan.FromMinutes(5),
                    TimeSpan.FromSeconds(1));

                var coord = new Coordinate(geoposition.Coordinate);
                return coord;
            }
            catch
            {
                return null;
            }

        }
    }
}
